package com.ruoyi.common.core.domain;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.utils.LongJsonDeserializer;
import com.ruoyi.common.utils.LongJsonSerializer;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Entity基类
 *
 * @author ruoyi
 */
@Data
public class PlusBaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * ID
     */
    @JsonSerialize(using = LongJsonSerializer.class)
    @JsonDeserialize(using = LongJsonDeserializer.class)
    @TableId(type = IdType.ASSIGN_ID)
    public Long id;

    /**
     * 创建者
     */
    @Excel(name = "创建者")
    @TableField(fill = FieldFill.INSERT)
    public String createBy;

    /**
     * 创建时间
     */
    @Excel(name = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date createTime;

    /**
     * 更新者
     */
    @Excel(name = "更新者")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    public String updateBy;

    /**
     * 更新时间
     */
    @Excel(name = "更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date updateTime;

    /**
     * 删除标记
     */
    public String delFlag;

    /** 备注 */
    @Excel(name = "备注")
    private String remark;

    /**
     * 请求参数
     */
    @TableField(exist = false)
    @Getter(AccessLevel.NONE)
    public Map<String, Object> timeParams;

    /**
     * 请求参数
     */
    @TableField(exist = false)
    @Getter(AccessLevel.NONE)
    public Map<String, Object> params;

    public Map<String, Object> getParams() {
        if (params == null) {
            params = new HashMap<>();
        }
        return params;
    }

    public Map<String, Object> getTimeParams() {
        if (timeParams == null) {
            timeParams = new HashMap<>();
        }
        return timeParams;
    }
}
